﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Transactions;
using AB.ServiceDirectory.BO;
using AB.ServiceDirectory.Commons.DataFilters;
using AB.ServiceDirectory.Entities;
using NUnit.Framework;

namespace AB.ServiceDirectory.TestScripts
{
    [TestFixture]
    class DirectorateTesting
    {
        private string _sortType;
        private int _startRowIndex;
        private int _maxRow;
        //private DirectorateBO _directorateBO = new DirectorateBO();
        [SetUp]
        public void SetUp()
        {
            _sortType = "DirectorateId";
            _startRowIndex = 0;
            _maxRow = 15;
        }
        public Directorate SetUpDirectorate()
        {
            var directorate = new Directorate
            {
                DirectorateName = "Directorate Name at " + DateTime.Now.ToShortTimeString(),
                AddressId = 1,
                BusinessId = 1,
                ContactId = 1
            };
            return directorate;
        }

        [Test]
        public void DirectorateList_FilterIsNull_ReturnCollection()
        {
            DirectorateFilter filter = null;
            var actual = BO.DirectorateBO.GetDirectorateList(filter, _sortType, _startRowIndex, _maxRow);
            Assert.IsNotNull(actual);
        }

        [Test]
        public void DirectorateList_LetterIsNullAndIncludeActiveIsTrue_ReturnCollection()
        {
            var filter = new DirectorateFilter { IncludeInactive = true };
            filter.SetBeginningLetters(new Collection<string> { "A", "B", "C", "D", "E" });
            var actual = BO.DirectorateBO.GetDirectorateList(filter, _sortType, _startRowIndex, _maxRow);
            Assert.IsNotNull(actual);
        }

        [Test]
        public void DirectorateList_LetterIsNullAndIncludeActiveFalse_ReturnCollection()
        {
            var filter = new DirectorateFilter { IncludeInactive = false };
            filter.SetBeginningLetters(new Collection<string> { "A", "B", "C", "D", "E" });
            var actual = BO.DirectorateBO.GetDirectorateList(filter, _sortType, _startRowIndex, _maxRow);
            Assert.IsNotNull(actual);
        }
        [Test]
        public void DirectorateList_LetterHasValueAndIncludeActiveTrue_ReturnCollection()
        {
            var filter = new DirectorateFilter
                             {
                                 IncludeInactive = true
                             }; filter.SetBeginningLetters(new Collection<string> { "A", "B", "C", "D", "E" });
            var actual = BO.DirectorateBO.GetDirectorateList(filter, _sortType, _startRowIndex, _maxRow);
            Assert.IsNotNull(actual);
        }

        [Test]
        public void DirectorateList_LetterHasValueAndIncludeActiveFalse_ReturnCollection()
        {
            var filter = new DirectorateFilter
                             {

                                 IncludeInactive = false
                             };
            filter.SetBeginningLetters(new Collection<string> { "A", "B", "C", "D", "E" });
            var actual = BO.DirectorateBO.GetDirectorateList(filter, _sortType, _startRowIndex, _maxRow);
            Assert.IsNotNull(actual);
        }

        [Test]
        public void GetDirectorateById_IdIsNegativeNumber_ReturnNull()
        {
            const int id = -1;
            var actual = DirectorateBO.GetDirectorateById(id);

            Assert.IsNull(actual);
        }

        [Test]
        public void GetDirectorateById_IdIsExistsInDatabase_ReturnObject()
        {
            const int id = 1;
            var actual = DirectorateBO.GetDirectorateById(id);

            Assert.IsNotNull(actual);
        }

        [Test]
        public void GetDirectorateById_IdIsNotExistsInDatabase_ReturnNull()
        {
            const int id = 0;
            var actual = DirectorateBO.GetDirectorateById(id);

            Assert.IsNull(actual);
        }
        [Test]
        public void AddDirectorate_AllIsInvalid_ReturnFalse()
        {
            using (var trans = new TransactionScope())
            {
                var directorate = SetUpDirectorate();
                directorate.DirectorateName = null;
                directorate.AddressId = -1;
                directorate.BusinessId = -1;
                directorate.ContactId = -1;
                var actual = BO.DirectorateBO.AddDirectorate(directorate);
                Assert.IsFalse(actual);
            }
        }

        [Test]
        public void AddDirectorate_DirectorateNameIsNull_ReturnFalse()
        {
            using (var trans = new TransactionScope())
            {
                var directorate = SetUpDirectorate();
                directorate.DirectorateName = null;
                var actual = BO.DirectorateBO.AddDirectorate(directorate);
                Assert.IsFalse(actual);
            }
        }

        [Test]
        public void AddressIdNotExistsInDatabase_ReturnFalse()
        {
            using (var trans = new TransactionScope())
            {
                var directorate = SetUpDirectorate();
                directorate.AddressId = -1;

                var actual = DirectorateBO.AddDirectorate(directorate);
                Assert.IsFalse(actual);
            }
        }

        [Test]
        public void BusinessIdNotExistsInDatabase_ReturnFalse()
        {
            using (var trans = new TransactionScope())
            {
                var directorate = SetUpDirectorate();
                directorate.BusinessId = -1;

                var actual = DirectorateBO.AddDirectorate(directorate);
                Assert.IsFalse(actual);
            }
        }

        [Test]
        public void ContactIdNotExistsInDatabase_ReturnFalse()
        {
            using (var trans = new TransactionScope())
            {
                var directorate = SetUpDirectorate();
                directorate.ContactId = -1;

                var actual = DirectorateBO.AddDirectorate(directorate);
                Assert.IsFalse(actual);
            }
        }
    }
}
